package com.example.selenium.video;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import lombok.Data;

import java.io.File;

@Data
public class VideoConsumer implements Runnable {
    private String url;

    public VideoConsumer() {
    }

    public VideoConsumer(String url) {
        this.url = url;
    }

    public static void main(String[] args) {
        String url = "https://v.source.zxxk.com/930e922b39d54d68988729a79639abbe/30c31ea00c3f42689005064743c346d6-5c13009701cd5bbc5c9458622e1dc881-ld-00001.ts?auth_key=1640877169-86bcf610b47c440e95be6143b254f482-xqFGUSLq-c65697d10a1fffa6730eacc81dda5404";
        int index = StrUtil.indexOfIgnoreCase(url, "?");
        HttpUtil.downloadFile(url, "D:\\" + "111.ts");
        String sub = StrUtil.sub(url, (index - 8), (index));
        System.out.println(sub);
    }

    @Override
    public void run() {
        int index = StrUtil.indexOfIgnoreCase(url, "?");
        String sub = StrUtil.sub(url, (index - 8), (index));
        String path = "D:\\baiduwangpan\\xuekewang\\video\\" + sub;
        File file = FileUtil.file(path);
        if (!file.exists()) {
            HttpUtil.downloadFile(url, path);
        }

    }

}
